@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
pushd "%SCRIPT_DIR%.."

if not exist .venv (
  echo venv not found. Creating...
  call scripts\make_venv.bat || exit /b 1
)

call .venv\Scripts\activate.bat
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple >nul
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple || exit /b 1

set "SCRIPT_PATH=%CD%\main.py"

pyinstaller --noconfirm --clean --onefile --windowed --name FileSyncTool --add-data "docs;docs" "%SCRIPT_PATH%"
if errorlevel 1 (
  echo PyInstaller failed. See messages above.
  popd
  exit /b 1
)

echo Build finished. See dist\FileSyncTool.exe

popd
